﻿using QFramework;

namespace GameJamLight
{
    public interface IKnockCheckSystem : ISystem
    {
        void Start();
        void Stop();
    }
    public class KnockCheckSystem : AbstractSystem, IKnockCheckSystem
    {
        private Timer mHitTimer;

        protected override void OnInit()
        {
            mHitTimer = new Timer();

            this.RegisterEvent<GameFailEvent>(e => mHitTimer.Stop());
            this.RegisterEvent<LevelPassEvent>(e => mHitTimer.Stop());

            PublicMono.Instance.OnUpdate += mHitTimer.Update;
        }

        void IKnockCheckSystem.Start()
        {
            mHitTimer.Start(1f, true, () =>
            {
                this.SendEvent<KnockWalkStickEvent>();
                //this.GetSystem<IAudioMgrSystem>().PlaySound("硬币落地2");
                Debuger.Log("Hit");
            });
        }

        void IKnockCheckSystem.Stop() => mHitTimer.Stop();
    }
}
